package javaCode.chapter02;

public class 强制类型转换 {

    public static void main(String[] args) {

        //演示强制类型转换
        //细节1
        int n1 = (int)1.8;
        System.out.println("n1="+n1);//1，造成精度损失

        int n2 = 2000;
        byte b1 = (byte)n2;
        System.out.println("b1"+b1);//造成 数据溢出

        //细节2: 强转符号只针对最近的操作数有效，往往会使用小括号提升优先级
        //int x = (int)10*3.5+6*1.5; // 编译错误 double -> int
        int y = (int)(10*3.5+6*1.5); //(int)44.0 -> 44

        //char类型可以保存int的常量值，但不能保存int的变量值，需要强转
        //char c1 = 100; ok
        //int m = 100; ok
        //char c2 = m; 错误
        //char c3 = (char)m; ok c3 = d
    }
}
